<?php
/**
 * A basic HTML object
 *
 */
abstract class DynaGrid_HTML_Object {
	/**
	 * Tagname of the object which is neccasary for drawing the HTML element
	 *
	 * @var string
	 */
	protected $tagname;
	/**
	 * Wehter the tag is selfclosing (XHTML valid)
	 *
	 * @var boolean
	 */
	protected $selfclosing = false;
	/**
	 * The inner content of the element. Can be null for element those do not contain any inner data 
	 * like a <input />. This property can be overwritten in the getHTML call.
	 *
	 * @var string
	 */
	protected $innerHTML;
	/**
	 * Array of properties for the HTML element/object. (e.g. class, id, onclick, etc)
	 *
	 * @var array
	 */
	private $properties = array();
	/**
	 * Draws the specific HTML object.
	 *
	 * @param string $innerHTML if you want to override the innerHTML member
	 * @return string
	 */
	public function getHTML($innerHTML=null) {
		$output = '<'.$this->tagname;
		foreach ($this->properties as $name=>$value) {
			$output .= ' '.$name.'="'.$value.'" ';
		}
		if(!$this->selfclosing) {
			$output .= '>';		
			$output .= !is_null($innerHTML) ? $innerHTML : $this->innerHTML;
			$output .= '</'.$this->tagname.'>';
		} else {
			$output .= '/>';
		}

		return $output;	
	}
	/**
	 * Add a HTML property to the HTML object (e.g. class, id, onclick, etc)
	 *
	 * @param string $name
	 * @param string $value
	 */
	public function __set($name,$value) {
		$this->properties[$name] = $value;
	}
}